package com.ziyun.erp.web.modules.storeMaterialCheck.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.storeMaterialCheck.entity.StoreMaterialCheckDetailEntity;
import com.ziyun.erp.modules.storeMaterialCheck.service.StoreMaterialCheckDetailService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 门店耗材盘点明细表
 *
 * @author xueqz
 * @email 
 * @date 2019-01-17 14:40:13
 */
@RestController
@RequestMapping("storeMaterialCheck/storematerialcheckdetail")
public class StoreMaterialCheckDetailController {
    @Autowired
    private StoreMaterialCheckDetailService storeMaterialCheckDetailService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("storeMaterialCheck:storematerialcheckdetail:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = storeMaterialCheckDetailService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{detailId}")
    @RequiresPermissions("storeMaterialCheck:storematerialcheckdetail:info")
    public R info(@PathVariable("detailId") Integer detailId){
        StoreMaterialCheckDetailEntity storeMaterialCheckDetail = storeMaterialCheckDetailService.selectById(detailId);

        return R.ok().put("storeMaterialCheckDetail", storeMaterialCheckDetail);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("storeMaterialCheck:storematerialcheckdetail:save")
    public R save(@RequestBody StoreMaterialCheckDetailEntity storeMaterialCheckDetail){
        storeMaterialCheckDetailService.insert(storeMaterialCheckDetail);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("storeMaterialCheck:storematerialcheckdetail:update")
    public R update(@RequestBody StoreMaterialCheckDetailEntity storeMaterialCheckDetail){
        ValidatorUtils.validateEntity(storeMaterialCheckDetail);
        storeMaterialCheckDetailService.updateAllColumnById(storeMaterialCheckDetail);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("storeMaterialCheck:storematerialcheckdetail:delete")
    public R delete(@RequestBody Integer[] detailIds){
        storeMaterialCheckDetailService.deleteBatchIds(Arrays.asList(detailIds));

        return R.ok();
    }

}
